package com.kgcx.coupon.controller;

import com.kgcx.common.annotation.validator.Validator;
import com.kgcx.common.bean.RequestData;
import com.kgcx.common.bean.ReturnData;
import com.kgcx.common.controller.BaseController;
import com.kgcx.coupon.domain.CouponInfo;
import com.kgcx.coupon.domain.CouponType;
import com.kgcx.coupon.service.CouponInfoService;
import com.kgcx.coupon.service.CouponTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(description = "优惠卷接口", tags = "优惠卷接口")
@RestController
@RequestMapping("coupon")
public class CouponController extends BaseController {

    @Autowired
    private CouponInfoService couponInfoService;
    @Autowired
    private CouponTypeService couponTypeService;


    @ApiOperation(value = "前台查询可用优惠卷", httpMethod = "GET", notes = "计算价格的时候查询当前订单可用的优惠卷"
    )
    @ApiImplicitParams({
            @ApiImplicitParam(name = "customerId", value = "用户ID", required = true, paramType = "query", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "pageNum", value = "分页号", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "分页行数", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "vehiclePurposeOot", value = "优惠卷用车类型", required = false, paramType = "query", dataType = "String", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "availableCityOot", value = "城市ID", required = false, paramType = "query", dataType = "String", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "orderTypeOot", value = "优惠服务类型", required = false, paramType = "query", dataType = "String", dataTypeClass = Long.class),
            //@ApiImplicitParam(name = "expTimeGe", value = "优惠卷过期时间，大于，传递下单时间戳", required = false, paramType = "query", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "fareTypeOot", value = "运价类型 1：常规价 2：套餐价 3：一口价", required = false, paramType = "query", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "orderChannelOot", value = "使用渠道：1=app，2=小程序", required = false, paramType = "query", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "useTypeOot", value = "使用者：1=本人使用，2=替他人叫车使用", required = false, paramType = "query", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "triggerLe", value = "触发金额,小于等于", required = true, paramType = "query", dataType = "int", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "planDepartTime", value = "计划出发时间", required = false, paramType = "query", dataType = "int", dataTypeClass = Long.class)

    })
    @GetMapping("queryUsableCoupon")
    public ReturnData<List<CouponInfo>> queryUsableCoupon() {
        RequestData rd = this.getRequestData();
        return new ReturnData<>(couponInfoService.queryUsableCoupon(rd));
    }

    @ApiOperation(value = "根据订单查询可使用的优惠卷", httpMethod = "GET", notes = "根据订单查询可使用的优惠卷"
    )
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderNo", value = "订单编号", required = true, paramType = "query", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "pageNum", value = "分页号", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "分页行数", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class)
    })
    @GetMapping("queryUsableCouponByOrderNo")
    public ReturnData<List<CouponInfo>> queryUsableCouponByOrderNo() {
        RequestData rd = this.getRequestData();
        return new ReturnData<>(couponInfoService.queryUsableCouponByOrderNo(rd));
    }

    @ApiOperation(value = "修改优惠卷状态", httpMethod = "POST", notes = "修改优惠卷状态"
    )
    @ApiImplicitParams({
            @ApiImplicitParam(name = "couponId", value = "优惠卷id", required = true, paramType = "query", dataType = "long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "state", value = "状态，1未使用，2已使用，3使用中", required = true, paramType = "query", dataType = "long", dataTypeClass = Long.class),
    })
    @PostMapping("updateCouponState")
    public ReturnData updateCouponState(@RequestParam Long couponId, @RequestParam Long state) {
        couponInfoService.updateCouponState(couponId, state);
        return new ReturnData();
    }

    @Validator
    @ApiOperation(value = "前台查询用户所有优惠卷", httpMethod = "GET", notes = "我的个人中心可用的优惠卷")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "customerId", value = "用户ID", required = true, paramType = "query", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "pageNum", value = "分页号", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "分页行数", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
    })
    @GetMapping("queryUserCoupon")
    public ReturnData<List<CouponInfo>> queryUserCoupon() {
        RequestData rd = this.getRequestData();
        return new ReturnData<>(couponInfoService.queryUserCoupon(rd));
    }

    @ApiOperation(value = "前台新增优惠卷", httpMethod = "POST", notes = "新增优惠卷的接口")
    @PostMapping("addCoupon")
    public ReturnData addCoupon(@RequestBody CouponInfo couponInfo) {
        couponInfoService.addCoupon(couponInfo);
        return new ReturnData();
    }

    @ApiOperation(value = "为用户添加优惠卷", httpMethod = "POST", notes = "为用户添加优惠卷")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "customerId", value = "乘客ID", required = true, paramType = "query", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(name = "couponTypeId", value = "优惠卷类型ID", required = true, paramType = "query", dataType = "Long", dataTypeClass = Long.class)
    })
    @PostMapping("addCouponByType")
    public ReturnData addCouponByType(@RequestParam Long customerId, @RequestParam Long couponTypeId) {
        couponInfoService.addCouponByType(customerId, couponTypeId);
        return new ReturnData();
    }

    @ApiOperation(value = "后台根据id查询优惠卷", httpMethod = "GET", notes = "这是用来查询优惠卷的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "kid", value = "优惠卷ID", required = true, paramType = "query", dataType = "Long", dataTypeClass = Long.class),
    })
    @GetMapping("getCouponInfo")
    public ReturnData<CouponInfo> getCouponInfo(@RequestParam Long kid) {
        CouponInfo couponInfo = couponInfoService.getCouponInfo(kid);
        return new ReturnData<>(couponInfo);
    }


    @ApiOperation(value = "后台删除优惠卷", httpMethod = "POST", notes = "这是用来删除优惠卷的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "kid", value = "优惠卷ID", required = true, paramType = "query", dataType = "Long", dataTypeClass = Long.class),
    })
    @PostMapping("removeCouponInfo")
    public ReturnData removeCouponInfo(@RequestParam Long kid) {
        couponInfoService.removeCouponInfo(kid);
        return new ReturnData();
    }

    @ApiOperation(value = "后台修改优惠卷", httpMethod = "POST", notes = "这是用来修改优惠卷的接口")
    @PostMapping("updateCouponInfo")
    public ReturnData updateCouponInfo(@RequestBody CouponInfo couponInfo) {
        couponInfoService.updateCouponInfo(couponInfo);
        return new ReturnData();
    }


    @ApiOperation(value = "后台根据id查询优惠卷类型", httpMethod = "GET", notes = "这是用来查询优惠卷类型的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "kid", value = "主键id", required = true, paramType = "query", dataType = "Integer", dataTypeClass = Integer.class)
    })
    @GetMapping("getCouponType")
    public ReturnData<CouponType> getCouponType(@RequestParam Long kid) {
        return new ReturnData<>(couponTypeService.getCouponType(kid));
    }

    @ApiOperation(value = "后台分页查询所有优惠卷", httpMethod = "GET", notes = "这是用来查询优惠卷的接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "页容量", required = false, paramType = "query", dataType = "int", dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "orderBy", value = "排序", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "numbered", value = "编号抬头", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "couponNameLike", value = "名称，模糊", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "orderTypeOot", value = "服务类型", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "useChannelOot", value = "渠道", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class),
            @ApiImplicitParam(name = "availableCityOot", value = "城市", required = false, paramType = "query", dataType = "String", dataTypeClass = String.class),
    })
    @GetMapping("getCouponTypeList")
    public ReturnData<List<CouponType>> getCouponTypeList() {
        return new ReturnData<>(couponTypeService.getCouponTypeList(this.getRequestData()));
    }

    @ApiOperation(value = "优惠卷类型新增", httpMethod = "POST", notes = "这是用来新增优惠卷类型的接口")
    @PostMapping("addCouponType")
    public ReturnData addCouponType(@RequestBody CouponType couponType) {
        couponTypeService.addCouponType(couponType);
        return new ReturnData();
    }

    @ApiOperation(value = "后台修改所有优惠类型", httpMethod = "POST", notes = "这是用来修改优惠卷类型的接口")
    @PostMapping("updateCouponType")
    public ReturnData updateCouponType(@RequestBody CouponType couponType) {
        couponTypeService.updateCouponType(couponType);
        return new ReturnData();
    }


}
